const App = getApp();
var template = require('../template/template.js');
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		userInfo: {}, // 用户信息
		orderCount: {}, // 订单数量
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {

	},
	navcato(e) {
		wx.redirectTo({
			url: '/' + e.currentTarget.dataset.urls
		})
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {
		template.tabbar("tabBar", 3, this) //0表示第一个tabbar
		if (wx.getStorageSync('token')) {
			// 获取当前用户信息
			this.getUserDetail();
		}
	},
	/**
	 * 获取当前用户信息
	 */
	getUserDetail() {
		let _this = this;
		App._post_form('user.order/listNum', {}, function(result) {
			_this.setData(result.data);
		});
	},

	/**
	 * 订单导航跳转
	 */
	onTargetOrder(e) {
		console.log(e.detail.formId)
		if (!wx.getStorageSync('token')) {
			App.doLogin();
			return false;
		}
		// 记录formid
		//App.saveFormId(e.detail.formId);
		let urls = {
			all: '/pages/order/index?type=all',
			delivery: '/pages/order/index?type=delivery',
			payment: '/pages/order/index?type=payment',
			received: '/pages/order/index?type=received',
			refund: '/pages/order/refund/index',
		};
		// 转跳指定的页面
		wx.navigateTo({
			url: urls[e.currentTarget.dataset.type]
		})
	},
	iflogin() {
		if (!wx.getStorageSync('token')) {
			App.doLogin();
			return false;
		}
	},
	/**
	 * 菜单列表导航跳转
	 */
	onTargetMenus(e) {
		if (!wx.getStorageSync('token')) {
			App.doLogin();
			return false;
		}

		let urls = {
			feedback: '/pages/feedback/index',
			collection: '/pages/collection/index',
			address: '/pages/address/index',
			order: '/pages/order/index?type=all',
			seaver: ''
		};
		// // 记录formId
		// App.saveFormId(e.detail.formId);
		wx.navigateTo({
			url: urls[e.currentTarget.dataset.type]
		})
	}
})
